var redis = require('redis');
var elasticsearch = require('elasticsearch');

var r_client = redis.createClient();
var e_client = new elasticsearch.Client({
    host: 'localhost:9200',    
    log: 'trace'
});


r_client.subscribe('messages');

r_client.on('message', function (channel, message) {

    var body = JSON.parse(message);
    console.log(body);
    var b = {
        email: body.author[0].address,
        user: body.author[0].name,
        category: body.category,
        message: body.message,
        '@timestamp': body.date
    }

    var stats = {
        index: 'messages',
        type: 'message',
        body: b
    }

    e_client.index(stats, function (err, resp) {});

});
